package com.njym.java.security.app.rest;


import com.njym.java.security.app.biz.FamilySlideshowBiz;
import com.njym.java.security.app.entity.FamilySlideshow;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.msg.TableResultResponse;
import com.njym.java.security.common.rest.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("familySlideshow")
public class FamilySlideshowController extends BaseController<FamilySlideshowBiz,FamilySlideshow> {

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public TableResultResponse<FamilySlideshow> list(String name) {
		Example example = new Example(FamilySlideshow.class);
		if (StringUtils.isNotBlank(name)) {
			example.createCriteria().andEqualTo("name", name);
		}
		example.createCriteria().andEqualTo("status",1).andEqualTo("deleted",0);;
		List list = baseBiz.selectByExample(example);
		return new  TableResultResponse<>(list.size(),baseBiz.selectByExample(example));
	}

	/**
	 * 随机获取一张首页轮播图
	 * @param name
	 * @return
	 */
	@RequestMapping(value = "/slide", method = RequestMethod.GET)
	@ResponseBody
	public ObjectRestResponse slide(String name) {
		List<FamilySlideshow> list = baseBiz.getSlide(name);
		Map<String,Object> map = new HashMap<>(2);
		map.put("data",list);
		map.put("total",list.size());
		return new ObjectRestResponse<>().rel(true).data(map);
	}

	/**
	 * 获取引导页的图（引导页归在轮播图管理中）
	 * @return
	 */
	@RequestMapping(value = "/getGuidingImages", method = RequestMethod.GET)
	@ResponseBody
	public ObjectRestResponse getGuidingImages() {
		List<FamilySlideshow> list = baseBiz.getGuidingImages();
		Map<String,Object> map = new HashMap<>(1);
		map.put("data",list);
		return new ObjectRestResponse<>().rel(true).data(map);
	}

}